// -----------------------------------------------------------------------
//  <copyright file="LocalServiceIntegrationEventsController.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2025 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://www.dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2025-02-19 23:02</last-date>
// -----------------------------------------------------------------------

using Dapr;
using DaprPlus.Authorization.Application.Commands;

namespace DaprPlus.Identity.Api.Controllers;

[Route("api/integration-events")]
public class LocalServiceIntegrationEventsController(IMediator mediator) : ApiControllerBase
{
    private const string PubSubName = "pubsub";

    [HttpPost("remove-resource-cache")]
    [Topic(PubSubName, "IdentityApi_ResourceDeleted")]
    [Topic(PubSubName, "IdentityApi_ResourceUpdated")]
    public async Task<ActionResult> RemoveResourceCacheEventHandler([FromBody] RemoveResourceCacheCommand request)
    {
        await mediator.Send(request);
        return Accepted();
    }

    [HttpPost("remove-role-resource-cache")]
    [Topic(PubSubName, "IdentityApi_RoleResourceRemoved")]
    [Topic(PubSubName, "IdentityApi_RoleResourceSet")]
    public async Task<ActionResult> RemoveRoleResourceCacheEventHandler([FromBody] RemoveResourceAuthCacheCommand request)
    {
        await mediator.Send(request);
        return Accepted();
    }
}
